package com.xuan.yubi.bizmq;


import com.rabbitmq.client.Channel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.amqp.support.AmqpHeaders;
import org.springframework.messaging.handler.annotation.Header;
import org.springframework.stereotype.Service;

import java.io.IOException;

//@Service
@Slf4j
public class MqMessageConsumer {


    // 指定要监听的队列名称和消息确认方式
    @RabbitListener(queues = {"test_queue"}, ackMode = "MANUAL")
    public void receiveMessage(String message, Channel channel, @Header(AmqpHeaders.DELIVERY_TAG) long deliverTag) {
        log.info("receiveMessage message:{}", message);
        try {
            channel.basicAck(deliverTag, false);
        } catch (IOException e) {
            log.error("confirm message error: ", e);
        }
    }
}
